package com.server.controller;

import com.annnotion.Controller;
import com.annnotion.RequestBody;
import com.annnotion.RequestMapping;
import com.domain.LoginForm;
import com.session.Session;
import com.session.SessionManager;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * Created by Greg.chen on 2016-03-19.
 */
@Component
@Controller
public class PlayerController {

    /**
     * 登录帐号
     * @param form
     */
    @RequestMapping(uri = "/login")
    public String login(@RequestBody LoginForm form, Session session) throws Exception {
        if(!form.getPassword().equalsIgnoreCase("123"))
            throw new Exception("password not match");

        int id = new Random().nextInt(1000000);
        SessionManager.putSession(id, session);

        return String.valueOf(id);
    }
}
